package application;

import java.io.File;
import java.io.FileInputStream;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class XMLUtil {

	public static Document getDocument(File f)
	{
		Document doc = null;
		
		try{
			
			doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new FileInputStream(f));
		}catch(Exception e){}
		
		return doc;
	}
	
	public static String getTextContent(Node n, String tag)
	{
		for(int i = 0; i < n.getChildNodes().getLength(); i++)
		{
			Node in = n.getChildNodes().item(i);
			if(in.getNodeName().equals(tag))
				return in.getTextContent();
			else
			{
				String text = getTextContent(in, tag);
				if(text == null)
					continue;
				else
					return text;
			}
		}
		return null;
	}
}
